package android.tong;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class LayoutChange extends Activity {
	public static final int CHG_ID = Menu.FIRST;
	public static final int EXIT_ID = Menu.FIRST + 1;
	
	private String[] data = {" Item-1 ", " Item-2 ", " Item-3 "};
	TextView tv;
	LinearLayout layout1, layout2;
	boolean selection = true;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		layout1 = (LinearLayout)inflate.inflate(R.layout.layoutchange, null);
		setContentView(layout1);
		TextView tx = (TextView)findViewById(R.id.tx);
		tx.setBackgroundResource(R.drawable.android);
		tx.setTextColor(Color.RED);
		
		layout2 = (LinearLayout)inflate.inflate(R.layout.list, null);
		ListView lv = (ListView)layout2.findViewById(R.id.list);
		lv.setBackgroundResource(R.drawable.girlandroid);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, data);
		lv.setAdapter(adapter);
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		super.onCreateOptionsMenu(menu);
		menu.add(0, CHG_ID, 0, "Change");
		MenuItem im = menu.findItem(CHG_ID);
		im.setIcon(R.drawable.icon);
		menu.add(0, EXIT_ID, 0, "Exit");
		im = menu.findItem(EXIT_ID);
		im.setIcon(R.drawable.tf);
		return true;
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case CHG_ID:
			selection = !selection;
			if (selection)
				this.setContentView(layout1);
			else
				this.setContentView(layout2);
			break;
		
		case EXIT_ID:
			finish();
			break;
		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}
	
	
	
}
